<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Simpla Admin</title>
    <!--                       CSS                       -->
    <!-- Reset Stylesheet -->
    <link rel="stylesheet" href="/back/css/reset.css" type="text/css"
          media="screen" />
    <!-- Main Stylesheet -->
    <link rel="stylesheet" href="/back/css/style.css" type="text/css"
          media="screen" />
    <link rel="stylesheet" href="/back/css/invalid.css" type="text/css"
          media="screen" />
    <!--                       Javascripts                       -->
    <!-- jQuery -->
    <script type="text/javascript"
            src="/back/scripts/jquery-2.1.0.min.js"></script>
    <!-- jQuery Configuration -->
    <script type="text/javascript"
            src="/back/scripts/simpla.jquery.configuration.js"></script>
    <!-- Facebox jQuery Plugin -->
    <script type="text/javascript" src="/back/scripts/facebox.js"></script>
    <!-- jQuery WYSIWYG Plugin -->
    <script type="text/javascript" src="/back/scripts/jquery.wysiwyg.js"></script>
    <style>
        body {
            overflow-x: hidden;
            overflow-y: hidden;
        }
    </style>

    <!-- TODO 自定义ajax请求 -->
    <script type="text/javascript" th:src="${contextPath + '/commons/js/myajax.js'}"></script>


    <script type="text/javascript" th:inline="javascript">
        $(function(){
            $("#homeframe").css("height", $(window).height())
            $("li ul:first").show();
            
            // 检查登录状态并加载用户信息
            checkLoginStatus();
        });

        function itemclick(ele){
            $("#homeframe").attr("src", ele.name);
            $(".current").removeClass("current");
            $(ele).addClass("current");
        }
        
        // 检查登录状态
        function checkLoginStatus() {
            $.ajax({
                url: '/api/admin/current',
                type: 'GET',
                success: function(response) {
                    if (response.code === 200) {
                        updateUserInfo(response.data);
                    } else {
                        // 未登录，跳转到登录页
                        window.location.href = '/admin/login';
                    }
                },
                error: function() {
                    // 请求失败，跳转到登录页
                    window.location.href = '/admin/login';
                }
            });
        }
        
        // 更新用户信息显示
        function updateUserInfo(user) {
            var userInfo = '你好, <font color="green">' + (user.realName || user.username) + '</font>';
            if (user.lastLoginTime) {
                userInfo += '<br><small>上次登录: ' + formatDateTime(user.lastLoginTime) + '</small>';
            }
            $('#user-info').html(userInfo);
        }
        
        // 格式化日期时间
        function formatDateTime(dateTimeStr) {
            if (!dateTimeStr) return '';
            var date = new Date(dateTimeStr);
            return date.toLocaleString('zh-CN', {
                year: 'numeric',
                month: '2-digit',
                day: '2-digit',
                hour: '2-digit',
                minute: '2-digit'
            });
        }
        
        // 注销登录
        function logout() {
            if (confirm('确定要注销登录吗？')) {
                $.ajax({
                    url: '/api/admin/logout',
                    type: 'POST',
                    success: function(response) {
                        alert('注销成功');
                        window.location.href = '/admin/login';
                    },
                    error: function() {
                        alert('注销失败，请重试');
                    }
                });
            }
        }
        
        // 修改密码
        function changePassword() {
            window.open('/backs/change_password', '_blank');
        }
    </script>


</head>
<body id="main_body">
<div id="body-wrapper">
    <!-- Wrapper for the radial gradient background -->
    <div id="sidebar">
        <div id="sidebar-wrapper">
            <!-- Sidebar with logo and menu -->
            <h1 id="sidebar-title">
                <a href="#">Simpla Admin</a>
            </h1>
            <!-- Logo (221px wide) -->
            <div style="width: 100%; text-align: center;"><img id="mylogo" src="/back/images/logo.png"
                             alt="Simpla Admin logo" style="margin: 10px;"/></div>
            <!-- Sidebar Profile links -->
            <div id="profile-links">
                <div id="user-info">加载中...</div>
                <br />
                <a href="javascript:void(0);" onclick="changePassword()" title="修改密码">修改密码</a> | 
                <a href="javascript:void(0);" onclick="logout()" title="注销登录">注销</a>
            </div>

            <!-- 引入菜单 -->
            <ul id="main-nav">
                <li><a class="nav-top-item"> 系统管理 </a>
                    <ul>
                        <li><a onclick="itemclick(this);" th:name="${contextPath + '/backs/language_manager'}" class="current">语言管理</a></li>
                        <li><a onclick="itemclick(this);" th:name="${contextPath + '/backs/language_text_config'}">多语种文本配置</a></li>
                    </ul>
                </li>
                <li><a class="nav-top-item"> 内容管理 </a>
                    <ul>
                        <li><a onclick="itemclick(this);" th:name="${contextPath + '/backs/carousel_manager'}">轮播图管理</a></li>
                    </ul>
                </li>
                <li><a class="nav-top-item"> 产品管理 </a>
                    <ul>
                        <li><a onclick="itemclick(this);" th:name="${contextPath + '/backs/classify_manager'}">分类管理</a></li>
                        <li><a onclick="itemclick(this);" th:name="${contextPath + '/backs/product_manager'}">产品管理</a></li>
                    </ul>
                </li>
                <li><a class="nav-top-item"> 客户管理 </a>
                    <ul>
                        <li><a onclick="itemclick(this);" th:name="${contextPath + '/backs/contact_manager'}">联系信息管理</a></li>
                    </ul>
                </li>
                <li><a class="nav-top-item"> 文件管理 </a>
                    <ul>
                        <li><a onclick="itemclick(this);" th:name="${contextPath + '/backs/image_manager'}">图片管理</a></li>
                        <li><a onclick="itemclick(this);" th:name="${contextPath + '/backs/image_enhancer'}">图片增强工具</a></li>
                    </ul>
                </li>
                <li><a class="nav-top-item"> 邮件管理 </a>
                    <ul>
                        <li><a onclick="itemclick(this);" th:name="${contextPath + '/api/mail/backs/mail_manager'}">邮件群发</a></li>
                        <li><a onclick="itemclick(this);" th:name="${contextPath + '/mail-sender-config'}">发送方配置</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <div style="margin: 0 0 0 230px;">
        <!-- End #sidebar -->
        <iframe id="homeframe" name="homeframe" th:src="${contextPath + '/backs/language_manager'}"
                width="100%" scrolling="auto"  />
    </div>
</div>


</body>
<!-- Download From www.exet.tk-->
</html>
